/**
 * 
 */
package etric.mapmaker.tools;

/**
 * This class represnts the Bounding Box from a specific area
 * @author etric
 */
public class BoundingBox
{
	/** coordinates from the bounding box edges */
	double pointN = 0;
	double pointE = 0;
	double pointS = 0;
	double pointW = 0;
	
	/** Earth radius in Km */
	int rad = 6371; 
	
	public BoundingBox()
	{
		
	}
	
	public BoundingBox(double pointN, double pointE, double pointS, double pointW)
	{
		this.pointN = pointN;
		this.pointE = pointE;
		this.pointS = pointS;
		this.pointW = pointW;
	}
	
	/**
	 * @return width of the box in meters 
	 */
	public int boxWidth()
	{
		// Convert to radians
		double top    = Math.toRadians(this.pointN);
	    double bottom = Math.toRadians(this.pointS);
	    
	    double distance = Math.acos(Math.sin(top) * Math.sin(bottom) + Math.cos(top) * Math.cos(bottom)) * this.rad;
	    
	    return (int)(distance * 1000); // return distance in m
	}

	/**
	 * calculates the long center point of the map
	 */
	public double getCenterLong()
	{
		double diffX = Math.max(this.pointW, this.pointE) - Math.min(this.pointW, this.pointE);
		
		return Math.min(this.pointW, this.pointE) + diffX/2;
	}
	
	/**
	 * calculates the lat center point of the map
	 */
	public double getCenterLat()
	{		
		double diffY = Math.max(this.pointN, this.pointS) - Math.min(this.pointN, this.pointS);
		
		return Math.min(this.pointN, this.pointS) + diffY/2;
	}
	
	/**
	 * @return the pointE
	 */
	public double getPointE() {
		return pointE;
	}

	/**
	 * @param pointE the pointE to set
	 */
	public void setPointE(double pointE) {
		this.pointE = pointE;
	}

	/**
	 * @return the pointN
	 */
	public double getPointN() {
		return pointN;
	}

	/**
	 * @param pointN the pointN to set
	 */
	public void setPointN(double pointN) {
		this.pointN = pointN;
	}

	/**
	 * @return the pointS
	 */
	public double getPointS() {
		return pointS;
	}

	/**
	 * @param pointS the pointS to set
	 */
	public void setPointS(double pointS) {
		this.pointS = pointS;
	}

	/**
	 * @return the pointW
	 */
	public double getPointW() {
		return pointW;
	}

	/**
	 * @param pointW the pointW to set
	 */
	public void setPointW(double pointW) {
		this.pointW = pointW;
	}

}
